Now I want to make a chuck spawn or two spawn.
Chuck, If he dies, he's down here fighting zombies.
People might be shooting at him.
We're always going to want to chuck around, so let's grab Chuck.
He's in the workspace.
There's the workspace, there's Chuck, Drag him down to server storage.
Here it is.
Server storage.
I'll just put them on the top level there or first level of server storage.
Now I'm going to go to session utils and write my spawning routine there.
Session utils which is in server script service.
This is the top.
We'll go down there a little bit, maybe under start way.
We didn't do anything with that.
There's a few things we've got to clean up yet.
Let's make a function local function utils.
There we go.
And I'll say spawn and pick and we'll pass.
In the MPC we want to spawn.
This time it's Chuck, but maybe we'll get another NPC like a shopkeeper or something.
All right, so first thing we've got to do, if we're spawning an MPC is check to make sure it's not
already in the world.
Right.
So let's do a local, make a variable for NPC in world and we will check to see if the MPC is in the
world.
All of my MPC is not the monsters, but the MPC are in the workspace, so this isn't going to be a problem.
But we might have to be more sophisticated with our code if we start putting them in folders.
All right.
So I'm going to do a fine first child because he might not be there.
If you wait for child and he's dead, you're going to get hung up here in the code.
So let's look for the MPC.
If he's in the world, fine.
If not MPC in world, then we've got to create a new one, let's call it we'll say local, new and NPC,
and we're going to get them from server storage.
Right?
I got a variable for server storage.
We can do a wait for child here because we know it's in server storage.
We put it there.
I was an NPC and then we'll just clone it.
There we go.
So we did a few things in that in that line.
Now I'll do NPC if I can get my NPC.
Oh new NPC.
Sorry parent will be the workspace.
There we go.
We got our NPC in the workspace but we still have to call us, right?
We haven't called it.
Where do we call?
Let's call it from the wav loop.
You know, there's a wave loop perhaps right under start wave.
Let's do a utils spawn and pick
Chuck.
Oh, my gosh.
Norris, make sure you spell it right.
I know I kind of butchered that, but if we go down here, click on Chuck Norris.
Look at the name.
You might even want to just copy it.
If you're typing is a little bit like mine is today.
Control V.
There we go.
Now we got Chuck Norris.
We're not going to be able to kill him very easily, though, because he's really, really strong.
So let's go to replicated storage.
I have a simple pistol for my character inside the damage on the simple pistol.
Let's crank that up.
Let's crank it up to 100 because Chuck has a health of 400.
But also on Chuck, let's find Chuck again.
Server storage.
Chuck Norris.
I don't know if you noticed, but we don't have the health bar above him with his name tag and everything.
Let's go ahead and change that so we could see his health.
Chuck Norris.
Humanoid.
Look for the display distance type on the humanoid.
We'll set it to viewer.
Now we can see his health.
And we got one more thing to do to Chuck.
Let's open up the move NPC and I want to make sure that when he dies, we clear him from the workspace.
Right?
Because if we find Chuck, even though he's dead, we're not going to spawn a new Chuck.
So I'm going to do I have the humanoid, I have the eye humanoid of Chuck and we'll do a dot die event,
connect that to a function.
And then I'll just say game dot debris, colon, add item I NPC, which is Chuck Norris, and then we'll
say 2 seconds.
So we'll clean the debris up from Chuck 2 seconds after he dies, it'll remove him from the world.
And that way we can spawn a new Chuck.
I think we're good to go.
Let's go ahead.
Open that up, play from here, see what's going on.
So we should see a chuck pretty soon.
Any minute.
There he is.
So he spawns into the world pretty soon.
Ooh.
Get a coin.
I think they changed run animation on my on our characters in the last update.
I'm going to shoot Chuck.
I got to get back up, though, because Chuck's pretty tough.
All right.
Oh, that's right.
We don't have them attacking us yet.
So there's Chuck again.
All right?
That's right.
We got to do we have to make Chuck attack us when we shoot him.
I like that health bar.
Oh, let's add health to health regeneration to Chuck.
This is how we do that.
This is an easy way.
We're going to open up the workspace while we're playing.
We're going to find our character Semtech Nitro one and then get that health script.
This is the health region.
Click on it, right click, and then I'll do a copy.
You have to turn the game off or it won't save when you go to paste it.
All right.
Now we're going to look for Chuck Norris.
Luckily, I have them right here under server storage.
And I'm going to paste into now.
He's going to have health regeneration.
It's actually a simple script.
We could have wrote it ourself, but it's going to regenerate his health just like a player.
So he's getting more and more player like.
So the next video will add dynamic tagging so that people can become enemies if they hurt Chuck.